package com.yyge.controller;

import com.yyge.dto.ResultCode;
import com.yyge.entity._____;
import com.yyge.service._____Service;
import com.yyge.dto.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yyge.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.crypto.spec.PSource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/__.__")
public class _____Controller extends BaseController {
    // 注入业务逻辑层
    private _____Service service;

    @Autowired/*自动装配*/
    public void setService(_____Service __.__Service){
        this.service=__.__Service;
    }

    @GetMapping/* GET(SELECT): 查询 */
    public R get(PageVo vo,_____ __.__) throws Exception  {

        QueryWrapper<_____> warpper = new QueryWrapper<>();
        QueryWrapper queryWrapper = this.getWrapper(__.__,warpper);
        PageVo pageVo =this.page(vo.getPageNum(),vo.getPageSize(),pageInfo ->service.page(pageInfo,queryWrapper));
        return R.ok(pageVo);
    }


    @PostMapping/* POST(CREATE): 新增&登陆 */
    public R post(@RequestBody _____ __.__){
        Boolean i=service.save(__.__);
        return i?R.ok("新增成功！"):R.error(ResultCode.SYSTEM_SERVICE_ADD_ERROR);
    }

    @PutMapping/* POST(CREATE): 更新 */
    public R out(@RequestBody _____ __.__){
        Boolean i=service.updateById(__.__);
        return i?R.ok("修改成功！"):R.error(ResultCode.SYSTEM_SERVICE_MODIFY_ERROR);
    }

    @PatchMapping/* PUT(UPDATE): 部分更新 */
    public R patch(@RequestBody _____ __.__){
        return null;
    }

    @DeleteMapping("/{id}")/* DELETE(DELETE): 删除&&批量删除 */
    public R delete(@PathVariable("id") Integer[] list){
        boolean i = service.removeByIds(Arrays.asList(list));
        return i?R.ok("修改成功！"):R.error(ResultCode.SYSTEM_SERVICE_DELETE_ERROR);
    }
}

